<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link href="Public/Admin/Flat/docs/assets/css/demo.css" rel="stylesheet">
	    <link rel="shortcut icon" href="Public/Admin/Flat/img/favicon.ico">
	    <!--ajax需要的文件-->
	    <script type="text/javascript" src="Public/uploadify/jquery-1.8.2.min.js"></script>
	    <script type="text/javascript" src="Public/uploadify/jquery.uploadify.min.js"></script>
	    <link rel="stylesheet" type="text/css" href="Public/uploadify/uploadify.css">
	    <!--载入百度编辑器-->
    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
		<script type="text/javascript">
			$(function(){
				$('[name=cid]').change(function(){
					var tid = $('option:selected').attr('tid');
					var hidden = '<input type="hidden" name="tid" value="'+tid+'" />';
					$.ajax({
						type:"post",
						url:"<?php echo U('getTypeAttr')?>",
						data:{tid : tid},
						dataType:'json',
						success:function(phpData){
							//规格(可选)
							var spec = '';
							//属性(不可选)
							var attr = '';
							$.each(phpData, function(k,v) {
								//规格
								if(v.tatype == 1){
									spec += '<tr class="info">'+
									'<td>'+v.taname+'</td>'+
									'<td>' +
										'<select name="spec['+v.taid+'][value][]" id=""><option value="">请选择</option>';
										$.each(v.tavalue,function(kk,vv){
											spec += '<option value="'+vv+'">'+vv+'</option>';
										});
										spec += '<select></td><td>附加价格：<input type="text" name="spec['+v.taid+'][extraprice][]" id="" /></td>'+
										'<td><span class="btn btn-success add-spec">增加规格</span></td></tr>';
								}else{//属性
									attr += '<tr class="info">'+
													'<td>'+v.taname+'</td>' +
													'<td>'+
													'<select name="attr['+v.taid+']" id=""><option value="">请选择</option>';
													$.each(v.tavalue,function(kk,vv){
														attr += '<option value="'+vv+'">'+vv+'</option>';
													});
									attr += '</select></td></tr>';
								}
							});
							//插入属性
							$('#attr').html(attr);
							//插入规格
							$('#spec').html(spec);
							//插入tid(都是通过post提交的,捎带把tid也提交)
							$('#tid').html(hidden);
						}
					});
				})
				
				//点击添加规格
				$('.add-spec').live('click',function(){
					//找到父级的tr
					var parentsTr = $(this).parents('tr');
					//把父级的tr克隆复制
					var cloneTr = parentsTr.clone();
					cloneTr.find('.add-spec').removeClass('add-spec btn-success').addClass('remove-spec btn-danger').html('删除规格');
					//插入下一行
					parentsTr.after(cloneTr);
				})
				//删除规格
				$('.remove-spec').live('click',function(){
					$(this).parents('tr').remove();
				})
			})
		</script>
	</head>
	<body>
		<form action="" method="post" enctype="multipart/form-data">
			<div class="alert alert-success">添加商品</div>
			<div class="form-group">
				<label for="exampleInputEmail1">商品名称</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入商品名称"  name="gname">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">所属分类</label>
				<select name="cid" class="form-control">
					<option value="0">请选择</option>
						<?php foreach ($cateData as $v){?>
							<option value="<?php echo $v['cid']?>" tid="<?php echo $v['tid']?>"><?php echo $v['_name']?></option>
						<?php }?>
				</select>
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">所属品牌</label>
				<select name="bid" class="form-control">
					<option value="">请选择</option>
					<?php foreach ($brandData as $v){?>
							<option value="<?php echo $v['bid']?>"><?php echo $v['bname']?></option>
					<?php }?>
				</select>
			</div>
			<!--保存隐藏域的tid-->
			<div class="form-group">
				<label for="exampleInputEmail1">单位</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入单位" value="件"  name="unit">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">市场价</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入市场价"  name="marketprice">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">商城价</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入商城价"  name="ShopPrice">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1">点击次数</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入点击次数"  name="click" value="666">
			</div>
			<div class="form-group">
				<label for="exampleInputEmail1" >总库存</label>
				<input id="exampleInputEmail1" class="form-control" type="text" placeholder="请输入点击次数"  name="stock" value="8888">
			</div>
			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">

			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
				
			</table>
			<!--保存隐藏域的tid-->
			<div id="tid"></div>
			<div class="form-group">
				<label for="exampleInputEmail1">列表图上传</label>
				<!-- 列表异步开始 -->
				<div lab="uploadFile">
				    <input id="f" type="file" multiple="true" name="pic">
				    <script type="text/javascript">
				        $(function() {
				            $('#f').uploadify({
				                'formData'     : {//POST数据
				                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
				                },
				                'fileTypeDesc' : '上传文件',//上传描述
				                'fileTypeExts' : '*.jpg;*.png;*.gif',
				                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
				                'uploader' : '<?php echo U('upload')?>',
				                'buttonText':'选择文件',
				                'fileSizeLimit' : '2000KB',
				                'uploadLimit' : 1,//上传文件数
				                'width':65,
				                'height':25,
				                'successTimeout':10,//等待服务器响应时间
				                'removeTimeout' : 0.2,//成功显示时间
				                'onUploadSuccess' : function(file, data, response) {
				                    //转为json
				                    data=$.parseJSON(data);
				                    //获得图片地址
				                    var imageUrl = data.url;
				                    var li="<li><img src='"+imageUrl+"' style='width:100px;'/><input type='hidden' name='pic' value='"+data.path+"'/></li>";
				                    $("#uploadList ul").prepend(li);
				                }
				            });
				        });
				    </script>
				    <div id="uploadList">
				        <ul style="list-style: none;">
							
				        </ul>
				    </div>
				</div>
			<!--列表异步结束-->
			</div>
			
			<div class="form-group">
				<label for="exampleInputEmail1">商品图册上传</label>
				<!-- 商品图册异步开始 -->
				<div lab="uploadFile">
				    <input id="sp" type="file" multiple="true" name="gd_pic">
				    <script type="text/javascript">
				        $(function() {
				            $('#sp').uploadify({
				                'formData'     : {//POST数据
				                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
				                },
				                'fileTypeDesc' : '上传文件',//上传描述
				                'fileTypeExts' : '*.jpg;*.png;*.gif',
				                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
				                'uploader' : '<?php echo U('upload1')?>',
				                'buttonText':'选择文件',
				                'fileSizeLimit' : '2000KB',
				                'uploadLimit' : 10,//上传文件数
				                'width':65,
				                'height':25,
				                'successTimeout':10,//等待服务器响应时间
				                'removeTimeout' : 0.2,//成功显示时间
				                'onUploadSuccess' : function(file, data, response) {
				                    //转为json
				                    data=$.parseJSON(data);
				                    //获得图片地址
				                    var imageUrl = data.url;
				                    var li="<li><img src='"+imageUrl+"' style='width:100px;'/><input type='hidden' name='gd_pic[]' value='"+data.path+"'/></li>";
				                    $("#sp ul").prepend(li);
				                }
				            });
				        });
				    </script>
				    <div id="sp">
				        <ul style="list-style: none;">
							
				        </ul>
				    </div>
				</div>
			<!--商品图册异步结束-->
			<br />
			<div class="form-group">
				<label for="exampleInputEmail1">商品详情</label>
				<!--调用百度编辑器-->
				<script id="editor" type="text/plain" style="width:100%;height:200px;" name="intro"></script>
		   	 	<script>
		        var ue = UE.getEditor('editor');
		    	</script>
			</div>
			<br />
			<div class="form-group">
				<label for="exampleInputEmail1">售后服务</label>
				<!--调用百度编辑器-->
				<script id="editor1" type="text/plain" style="width:100%;height:200px;" name="service"></script>
		   	 	<script>
		        var ue = UE.getEditor('editor1');
		    	</script>
			</div>
		<button class="btn btn-primary btn-block" type="submit"> 确定 </button>
	</form>
	</body>
</html>
